
var config;

const loadFile = lang => {
  config = require(`./config/${lang}/index`).default;
};

loadFile('zh-cn');

export default class {
  static locale(lang){
    loadFile(lang);
  }

  static getMsg(code) {
    if (typeof code !== 'string') {
      throw new Error('i18n getMsg field code is not string');
    }
    let value = _.get(config, code);
    if (value === undefined) {
      value = '';
    }

    return value;
  }

  static getDropDown(path, attrs){
    let dropDown = [];
    _.forEach(attrs, attr => {
      let label = this.getMsg(`${path}.${attr}`);
      dropDown.push({
        label:label,
        value:attr
      });
    });

    return dropDown;
  }
};
